package com.ly.base.chapter03;

import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

/**
 * 三种基本流
 *
 */
public class ANEffectiveDemo {
    record Hero(String name, int strength) { }
    public static void main(String[] args) {
        /**
         *
         * 三种基本流
         *
         */
        IntStream a = IntStream.of(97,98,99);
        LongStream b = LongStream.of(1L,2L,3L);
        DoubleStream c = DoubleStream.of(1.0,2.0,3.0);

        Stream<Integer> d = Stream.of(1, 2, 3);

        //1.1、mapToObj(int -> obj)转换为 obj 流
//        a.mapToObj(Character::toString).forEach(System.out::println);
        //1.2、boxed() 转换为 Integer 流

        //1.3、 summaryStatistics()
        //IntSummaryStatistics{count=3, sum=294, min=97, average=98.000000, max=99}
//        IntSummaryStatistics stat = a.summaryStatistics();
//        System.out.println(stat);
//        System.out.println(stat.getMax());
//        System.out.println(stat.getMin());
//        System.out.println(stat.getSum());
//        System.out.println(stat.getAverage());
//        System.out.println(stat.getCount());


        Stream<Hero> stream = Stream.of(
                new Hero("令狐冲",90),
                new Hero("风清扬",98)
        );

        stream.mapToInt(Hero::strength).forEach(System.out::println);
    }

}
